package com.onlyMe.world.components
{
	import com.flesler.componentas.core.Component;
	import com.onlyMe.world.components.base.BaseIsleComponent;
	import com.onlyMe.world.components.control.ControlComponent;
	import com.onlyMe.world.components.grababble.GrababbleComponent;
	import com.onlyMe.world.components.inventory.InventoryComponent;
	import com.onlyMe.world.components.movement.MovementComponent;

	public final class ComponentCreator
	{
		private static const CLASS_MAP:Object = {
			grababble:GrababbleComponent,
			inventory:InventoryComponent,
			moves:MovementComponent,
			controlled:ControlComponent
		}
		
		public function ComponentCreator()
		{
		}
		
		public function create(node:XML):Component
		{
			var type:String = node.localName() as String;
			
			if (!CLASS_MAP[type])
				throw new Error(type + ' is not a valid component type');
			
			var component:BaseIsleComponent = new CLASS_MAP[type]();
			component.deserialize(node);
			return component;
		}
	}
}